package com.yh.exception;

/**
 * 利用异常码的异常体系 优点： 只要写一个异常类，可以通过异常码（code）区分不同的异常 缺点： 不够直观
 * 
 * @author 湛锋
 *
 */

public class CodeException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 异常码
	 */
	private int code;
	/**
	 * 异常消息
	 */
	private String message;

	/**
	 * 
	 */
	public CodeException(int code) {
		super();
		this.code = code;
	}

	/**
	 * @param message
	 * @param cause
	 * @param enableSuppression
	 * @param writableStackTrace
	 */
	public CodeException(int code, String message, Throwable cause, boolean enableSuppression,
			boolean writableStackTrace) {
		super(message, cause, enableSuppression, writableStackTrace);
		this.code = code;
		this.message = message;
	}

	/**
	 * @param message
	 * @param cause
	 */
	public CodeException(int code, String message, Throwable cause) {
		super(message, cause);
		this.code = code;
		this.message = message;
	}

	/**
	 * @param message
	 */
	public CodeException(int code, String message) {
		super(message);
		this.code = code;
		this.message = message;
	}

	/**
	 * @param cause
	 */
	public CodeException(int code, Throwable cause) {
		super(cause);
		this.code = code;
	}

	public String getMessage() {
		return message == null ? ("code." + code) : message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getCode() {
		return code;
	}

}
